import { menus } from '../../config/menu';
import hasPerm from '@/permission/hasPerm'

/**
 * 获取可访问的菜单列表
 * @param loginUser
 * @param menuItems
 */
const getAccessibleMenu = (loginUser: API.User, menuItems = menus) => {
  return menuItems.filter((item) => {
    if (!hasPerm(loginUser, item.needPerm)) {
      return false;
    }
    if (item.children) {
      item.children = getAccessibleMenu(loginUser, item.children);
    }
    return true;
  });
};


export default getAccessibleMenu;
